import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { svgLoader } from './src/utils/svg-loader.js'
/* 自动导入组件 */
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// @ts-ignore
import ElementPlus from 'unplugin-element-plus/vite' // 按需导入样式

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    eslintPlugin({
      cache: false// 禁用eslint缓存
    }),
    vueJsx({
      // options are passed on to @vue/babel-plugin-jsx
    }),
    svgLoader('/src/assets/svg/'),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    ElementPlus({
      useSource: true
    })
  ],
  resolve: {
    // Vite路径别名配置
    alias: {
      '@': resolve(__dirname, './src') // @代替src
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "@/styles/element/index.scss" as *;' // 自定义elementPlus主题
      }
    }
  },
  server: {
    port: 8888,
    open: true,
    host: '0.0.0.0',
    proxy: {
      // 选项写法
      '/dev-api': {
        target: 'http://192.168.1.4:9900',
        changeOrigin: true,
        // ws: true,
        rewrite: (path) => path.replace(/^\/dev-api/, '')
      }
    }
  }
})
